package cn.gok.server.service.impl;

import cn.gok.common.dao.goods.GoodsBrandMapper;
import cn.gok.common.entity.goods.GoodsBrand;
import cn.gok.server.service.GoodsBrandService;
import cn.gok.utils.DateUtil;
import cn.gok.utils.UserContext;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: DxlinY
 * @apiNote:
 * @date: 2020/10/19
 * @time: 17:32
 */
@Service
@Slf4j
public class GoodsBrandServiceImpl implements GoodsBrandService {

    @Autowired
    private GoodsBrandMapper goodsBrandMapper;

    @Override
    public PageInfo pageInfo(Object target) {
        QueryWrapper <GoodsBrand> wrapper = new QueryWrapper <>();
        wrapper.setEntity((GoodsBrand) target);
        PageInfo <GoodsBrand> goodsBrandPageInfo = new PageInfo <>(goodsBrandMapper.selectList(wrapper));
        log.info("商品品牌列表获取成功{}", goodsBrandPageInfo);
        return goodsBrandPageInfo;
    }

    @Override
    public int insertBrand(GoodsBrand goodsBrand) {
        goodsBrand.setCreateBy(UserContext.user().getUserName());
        goodsBrand.setCreateTime(DateUtil.nowDateTime());
        goodsBrand.setUpdateBy(UserContext.user().getUserName());
        goodsBrand.setUpdateTime(DateUtil.nowDateTime());
        log.info("商品品牌新增{}", goodsBrand);
        return goodsBrandMapper.insert(goodsBrand);
    }

    @Override
    public int deleteByIds(List <Integer> ids) {
        log.info("批量删除商品品牌{}", ids);
        return goodsBrandMapper.deleteBatchIds(ids);
    }

    @Override
    public int updateById(GoodsBrand goodsBrand) {
        goodsBrand.setCreateBy(UserContext.user().getUserName());
        goodsBrand.setCreateTime(DateUtil.nowDateTime());
        goodsBrand.setUpdateBy(UserContext.user().getUserName());
        goodsBrand.setUpdateTime(DateUtil.nowDateTime());
        log.info("修改商品品牌{}", goodsBrand);
        return goodsBrandMapper.updateById(goodsBrand);
    }

    public GoodsBrand getBrandById(int id) {
        log.info("获取商品品牌信息{}", id);
        return goodsBrandMapper.selectById(id);
    }
}
